import math
from typing import List

from common.params import SoftParams, CasingParams
from model.soft.soft_common import AxialForceResult, data_init


# 计算液体阻力------通用公式----张力的那一堆
def get_fluid_resistance(tao_p: float, rate: float, v: float, L: float) -> float:
    # 定义计算元
    factor_a: float = 2 * math.pi * tao_p * L * v
    # print("factor_a为：",factor_a)
    factor_b: float = math.pow(rate, 2) - 1
    # print("factor_b为：", factor_b)
    factor_c: float = (math.pow(rate, 2) + 1) * math.log(rate)
    # print("factor_c为：", factor_c)
    # 计算结果
    res: float = (factor_a * factor_b) / (factor_c - factor_b)
    return res


# 计算下放流体阻力---工具
def tool_push_fluid(params: SoftParams, cur: AxialForceResult) -> float:
    # 获取套管信息列表
    casings: List[CasingParams] = params.casings
    # 获取最后一个套管的信息
    last_casing: CasingParams = casings[-1]
    rate = params.get_instrument_rate(cur.depth)
    res: float = get_fluid_resistance(params.tao_p, rate, params.v_push, params.L1)
    return res


# 计算上提流体阻力----工具
def tool_pull_fluid(params: SoftParams, cur: AxialForceResult) -> float:
    # 获取套管信息列表
    casings: List[CasingParams] = params.casings
    # 获取最后一个套管的信息
    last_casing: CasingParams = casings[-1]
    rate = params.get_instrument_rate(cur.depth)
    res: float = get_fluid_resistance(params.tao_p, rate, params.v_pull, params.L1)
    return res


def cable_push_fluid(params: SoftParams, cur: AxialForceResult) -> float:
    # 获取套管信息列表
    casings: List[CasingParams] = params.casings
    # 获取最后一个套管的信息
    last_casing: CasingParams = casings[-1]
    rate = params.get_cable_rate(cur.depth)
    res: float = get_fluid_resistance(params.tao_p, rate, params.v_push, cur.depth - params.L1)
    return res


def cable_pull_fluid(params: SoftParams, cur: AxialForceResult) -> float:
    # 获取套管信息列表
    casings: List[CasingParams] = params.casings
    # 获取最后一个套管的信息
    last_casing: CasingParams = casings[-1]
    rate = params.get_cable_rate(cur.depth)
    res: float = get_fluid_resistance(params.tao_p, rate, params.v_pull, cur.depth - params.L1)
    return res
